
#include "../detail/exception.hpp"

namespace mtl {

  class generic_category_impl : public error_category {
  public:
    virtual std::string name() const { return "generic"; }
    virtual std::string message(int ev) const {
      char buf[1024];
      return std::string(strerror_r(ev, buf, sizeof(buf)-1));
    }
  };

  class system_category_impl : public generic_category_impl {
  public:
    virtual std::string name() const { return "system"; }
  };

  const error_category& generic_category() {
    static generic_category_impl s_gcat;
    return s_gcat;
  }

  const error_category& system_category() {
    static system_category_impl s_scat;
    return s_scat;
  }

  error_condition error_category::default_error_condition(int ev) const {
    return error_condition(ev, *this);
  }

  error_condition error_code::default_error_condition() const {
    return category().default_error_condition(value());
  }
}

